package com.biz.primus.ms.order.convertor;

import com.biz.primus.common.utils.StringUtil;
import com.biz.primus.model.order.vo.DeliveryVO;
import com.biz.primus.model.order.vo.OrderDeliveryInfoVO;
import com.biz.primus.ms.order.dao.po.embeddable.OrderDeliveryInfo;
import org.codelogger.utils.BeanUtils;

/**
 * 物流信息转换器
 *
 * @author Tiger Feng
 * @date 2017年11月03日
 */
public class OrderDeliveryInfoConvertor {

    public static OrderDeliveryInfo vo2PO(OrderDeliveryInfoVO vo) {
        if (vo == null) {
            return null;
        }
        OrderDeliveryInfo po = new OrderDeliveryInfo();
        BeanUtils.copyProperties(vo, po);
        return po;
    }

    public static OrderDeliveryInfoVO po2VO(OrderDeliveryInfo po) {
        if (po == null) {
            return null;
        }
        OrderDeliveryInfoVO vo = new OrderDeliveryInfoVO();
        BeanUtils.copyProperties(po, vo);
        return vo;
    }

    /**
     * 用户选择的配送方式转订单配送模型,订单结算计算物流费用时使用
     *
     * @param selectDeliveryVO
     * @return
     */
    public static OrderDeliveryInfoVO selectedDeliveryVO2orderDeliveryInfoVO(DeliveryVO selectDeliveryVO) {
        if (selectDeliveryVO == null) {
            return null;
        }
        OrderDeliveryInfoVO orderDeliveryInfoVO = new OrderDeliveryInfoVO();
        orderDeliveryInfoVO.setDeliverType(selectDeliveryVO.getDeliverType());
        switch (selectDeliveryVO.getDeliverType()) {
            // 用户自提
            case USER_TRANSPORT:
                orderDeliveryInfoVO.setIsAppointment(selectDeliveryVO.getIsReserve());
                // 预约
                if (selectDeliveryVO.getIsReserve()) {
                    // 设置自提时间
                    orderDeliveryInfoVO.setExpectDeliveryTimestamp(selectDeliveryVO.getSelectedFetchTime());
                    // 设置自提门店
                }
                break;
            // 同城配送
            case STORE_TRANSPORT:
                orderDeliveryInfoVO.setIsAppointment(selectDeliveryVO.getIsReserve());
                // 预约
                if (selectDeliveryVO.getIsReserve()) {
                    // 设置 配送达到时间
                    orderDeliveryInfoVO.setExpectDeliveryTimestamp(selectDeliveryVO.getArriveTime());
                }
                break;
            // 第三方物流
            case THRID_TRANSPORT:
                // 设置物流公司
                break;
            default:
                break;
        }
        return orderDeliveryInfoVO;
    }
}
